[CALCITE-7646] CorrelateProjectExtractor does not handle nested field accesses cor0.field0.field1#5086
[CALCITE-7646] CorrelateProjectExtractor does not handle nested field accesses cor0.field0.field1#5086mihaibudiu wants to merge 3 commits into
CorrelateProjectExtractor does not handle nested field accesses cor0.field0.field1#5086Conversation
|
@zabetak according to git blame you wrote most of this code, so I took the liberty to request your review. |
9f0f80c to
d5bd389
Compare
|
I think the CI failure is transient, the tests pass locally. |
There shouldn't be any problems. I re-trigger sonar CI to double-check. |
|
The fact that I requested a review from @zabetak should not deter anyone else from reviewing this PR. I think it's a genuine improvement which will help our decorrelator handle more queries. |
|
Would it also be possible to add a few SQL-based test cases to QuidemTest? |
|
Sure, I will do that, but the results should not change, just the nature of the plan |
xuzifu666
left a comment
There was a problem hiding this comment.
In my view the overall implementation is ok and meets the objectives. Apart from suggesting the addition of QuidemTest, I have left two comments for your reference.
I have added a few quidem tests covering both decorrelators. |
|
Interestingly, Claude actually found a (related) bug in the original optimization, which forgot to preserve fields NOT moved into |
zabetak
left a comment
There was a problem hiding this comment.
Overall LGTM! Left some small comments/suggestions but nothing major.
| if (node instanceof RexFieldAccess) { | ||
| RexFieldAccess access = (RexFieldAccess) node; | ||
| if (access.getReferenceExpr() instanceof RexCorrelVariable) { | ||
| RexCorrelVariable var = (RexCorrelVariable) access.getReferenceExpr(); |
There was a problem hiding this comment.
var is a reserved keyword in JDK 10+ so to avoid any potential confusion I think its worth addressing this minor sonar warning.
| List<RexNode> callsWithCorrelationOverLeft = new ArrayList<>(); | ||
| for (RexNode callInRight : callsWithCorrelationInRight) { | ||
| callsWithCorrelationOverLeft.add(replaceCorrelationsWithInputRef(callInRight, builder)); | ||
| if (isDirectFieldAccess(callInRight, correlate.getCorrelationId())) { |
There was a problem hiding this comment.
How important is to have this condition? I understand that it tries to block "trivial" correlated expressions from generating redundant column references but it shouldn't lead to incorrect plans.
There was a problem hiding this comment.
Actually this is the bug that leads to the two crashes highlighted in some of the tests.
You need to put the field in the list of required columns.
| # 4 test cases for [CALCITE-7646] CorrelateProjectExtractor | ||
| # does not handle nested field accesses cor0.field0.field1. | ||
|
|
||
| # All queries use LATERAL, which converts directly to a Correlate. |
There was a problem hiding this comment.
Since the queries make use of lateral they fit better in the lateral.iq file.
| !use scott | ||
|
|
||
| # Before the fix planning failes with | ||
| # "Mappings$NoElementException: source #0 has no target in mapping". |
There was a problem hiding this comment.
The problem/failure (along with stacktrace information) are much more useful in the Jira description than in comments in the code. Users encountering a problem will first search on Google/Jira before digging into the code.
For reviewers its also easier to understand the context of the work by reading the problem description first.
There was a problem hiding this comment.
I will move the error descriptions in Jira and delete them from the comments
| !if (use_new_decorr) { | ||
| EnumerableCalc(expr#0..3=[{inputs}], expr#4=['SALES':VARCHAR(14)], expr#5=[=($t1, $t4)], DD=[$t2], X=[$t3], $condition=[$t5]) | ||
| EnumerableCorrelate(correlation=[$cor1], joinType=[inner], requiredColumns=[{0}]) | ||
| EnumerableCalc(expr#0..2=[{inputs}], proj#0..1=[{exprs}]) | ||
| EnumerableTableScan(table=[[scott, DEPT]]) | ||
| EnumerableCalc(expr#0=[{inputs}], expr#1=[$cor1], expr#2=[$t1.DEPTNO], DD=[$t2], X=[$t0]) | ||
| EnumerableUncollect | ||
| EnumerableCalc(expr#0=[{inputs}], expr#1=[$cor1], expr#2=[$t1.DEPTNO], expr#3=[100], expr#4=[+($t2, $t3)], expr#5=[ARRAY($t4)], EXPR$0=[$t5]) | ||
| EnumerableValues(tuples=[[{ 0 }]]) | ||
| !plan | ||
| !} |
There was a problem hiding this comment.
The new decorrelator is not using the CorrelateProjectExtractor so to some extend this test is unrelated to the fix and somewhat redundant. Is there something specific that we want to check in the plan?
| !if (use_old_decorr) { | ||
| EnumerableCalc(expr#0..3=[{inputs}], DD=[$t2], X=[$t3]) | ||
| EnumerableCorrelate(correlation=[$cor1], joinType=[inner], requiredColumns=[{0, 1}]) | ||
| EnumerableCalc(expr#0..2=[{inputs}], expr#3=[100], expr#4=[+($t0, $t3)], expr#5=[ARRAY($t4)], expr#6=['SALES':VARCHAR(14)], expr#7=[=($t1, $t6)], DEPTNO=[$t0], $f3=[$t5], $condition=[$t7]) | ||
| EnumerableTableScan(table=[[scott, DEPT]]) | ||
| EnumerableCalc(expr#0=[{inputs}], expr#1=[$cor1], expr#2=[$t1.DEPTNO], DD=[$t2], X=[$t0]) | ||
| EnumerableUncollect | ||
| EnumerableCalc(expr#0=[{inputs}], expr#1=[$cor1], expr#2=[$t1.$f3], EXPR$0=[$t2]) | ||
| EnumerableValues(tuples=[[{ 0 }]]) | ||
| !plan |
There was a problem hiding this comment.
Apart from the fact that the query runs (does not crash) and produces correct results what do we want to assert/verify in the query plan?
If we don't really care about the query plan then we should skip it. If there is something that we need to validate then an extra comment would be helpful.
|
|
||
| # EnumerableRules.ENUMERABLE_CORRELATE_RULE is removed so that this test | ||
| # fails if the plan cannot be fully decorrelated. | ||
| !set planner-rules "-EnumerableRules.ENUMERABLE_CORRELATE_RULE" |
There was a problem hiding this comment.
Nice idea for ensuring that a plan is fully decorrelated although such test would fit better in RelDecorrelatorTest where it would be more readable.
… accesses cor0.field0.field1 Signed-off-by: Mihai Budiu <mbudiu@feldera.com>
Signed-off-by: Mihai Budiu <mbudiu@feldera.com>
Signed-off-by: Mihai Budiu <mbudiu@feldera.com>
|
@zabetak I have temporarily pushed the changes requested by your review as a second commit, for you to check. |
|



Jira Link
CALCITE-7646
Changes Proposed
These changes make the helper class slightly more capable, enabling more programs to be decorrelated.